<template>
  <el-dialog :title="formData.id?'编辑':'添加'" :visible.sync="modelShow">
    <el-form ref="couponForm" :model="formData" label-width="120px" :rules="formRules">
      <el-form-item label="字典组" prop="dictGroup">
        <el-input v-model="formData.dictGroup"/>
      </el-form-item>
      <el-form-item label="字典标识" prop="dictTag">
        <el-input v-model="formData.dictTag"/>
      </el-form-item>
      <el-form-item label="字典值" prop="dictValue">
        <el-input v-model="formData.dictValue"/>
      </el-form-item>
      <el-form-item label="字典描述">
        <el-input type="textarea" v-model="formData.dictDesc"/>
      </el-form-item>
      <el-form-item>
        <el-button @click="modelShow = false">取 消</el-button>
        <el-button type="primary" @click="submitForm()">确 定</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { saveOrUpdateApi } from '@/api/system/sysDict'

export default {
  name: 'SysDictForm',
  data(){
    return {
      modelShow:false,
      formData:{},
      formRules:{
        dictTag: [
          { required: true, message: '请输入字典标识', trigger: 'blur' }
        ],
        dictValue: [
          { required: true, message: '请输入字典值', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    opened(isEdit,row){
      this.formData = isEdit ? row:{};
      this.modelShow = true;
    },
    submitForm(){
      this.$refs['couponForm'].validate((valid) => {
        if (valid) {
          saveOrUpdateApi(this.formData).then(res => {
            this.modelShow = false
            this.$emit('refreshTable');
          })
        }
      })
    },
  }
}
</script>

<style scoped>

</style>
